package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.AwardRecordService;
import cn.huiyunche.base.service.mappers.ext.CAwardRecordViewMapper;
import cn.huiyunche.base.service.model.CAwardRecordExample;
import cn.huiyunche.base.service.vo.CAwardRecordAdminVo;
import cn.huiyunche.base.service.vo.PageVo;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AwardRecordServiceImpl implements AwardRecordService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AwardRecordServiceImpl.class);

    @Autowired
    private CAwardRecordViewMapper cAwardRecordViewMapper = null;

    /**
     * 领取 奖品记录列表
     *
     * @param page
     * @return
     * @throws BusinessException
     */
    @Override
    public Map<String, Object> list(PageVo page) {
        LOGGER.info("list params : {}", page);
        CAwardRecordExample example = new CAwardRecordExample();

        example.setLimitStart(page.getStartIndex());
        example.setLimitEnd(page.getPageSize());
        if (StringUtils.isNotBlank(page.getOrder())) {
            example.setOrderByClause(page.getOrder());
        } else {
            example.setOrderByClause("id DESC");
        }
        List<CAwardRecordAdminVo> cAwardRecords = this.getCAwardRecordViewMapper().selectByExample(example);
        page.setTotalRecord(this.getCAwardRecordViewMapper().countByExample(example));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("awards", cAwardRecords);
        map.put("page", page);

        return map;
    }

    public CAwardRecordViewMapper getCAwardRecordViewMapper() {
        return this.cAwardRecordViewMapper;
    }

}
